<?php
// $Id$

/**
 * Controller_Socially 控制器
 */
class Controller_Socially extends Controller_Prepare
{
    /**
     * 服务社会专版，主要是项目介绍
     */
    public function actionIndex()
    {
      // Error handling 初步过滤获得的值，必须满足值类型
        $Gnews_id = isset($_GET['news_id']) && is_numeric($_GET['news_id']) ? $_GET['news_id'] : NULL;
      
      /**
         * 获取当前显示的新闻，如果是首页则将其重置为 NULL
         *
         * @var object $currentNews
         */
      $currentNews = NULL;
      if(isset($Gnews_id))
      {
         $currentNews = News::find('news_id = ?', $Gnews_id)->query();
      }

        // Error handling 如果恶意输入不存在的 ctgry_id 或 news_id，导致当前新闻不存在，则显示最新一条新闻
        // Error handling 检查 news_id
        if($currentNews && $currentNews->title == '')
        {
            $currentNews = NULL;
        }
      
      /**
         * 更新当前新闻"阅读"值 hasread = hasread + 1
         */
      if($currentNews)
      {
         News::meta()->updateDbWhere(new QDB_Expr('hasread = hasread + 1'), 'news_id = ?', $currentNews->news_id);
      }

      /**
       * CSS HIGHLIGHT
       *
       * @var string $css
       */
      $css = '';
      if($currentNews)
      {
         $css = "a[href*='_{$currentNews->news_id}.html']".HIGHLIGHT_CSS;
      }

        $this->_view['currentNews'] = $currentNews;
        $this->_view['css'] = $css;
    }
}